package com.example.gslih.myapplication.widget;

import android.os.Handler;

/**
 * create by gene 2018.11.26
 */
public class ClickBehavior {
    private boolean canClick=true;

    private ClickBehavior() { }

    public static ClickBehavior getInstance(){
        return ClickBehaviorHoler.instance;
    }

    private static class ClickBehaviorHoler{
        private static ClickBehavior instance = new ClickBehavior();
    }

    /**
     * 1s仅一次点击有效
     * @param oneSecondOnceListenner
     */
    public void oneSecondOnceEffective(OneSecondOnceListenner oneSecondOnceListenner){
        if (canClick){
            canClick =false;
            oneSecondOnceListenner.effective();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    canClick = true;
                }
            },1000);
        }
    }

    //点击接口
    public interface OneSecondOnceListenner{
        void effective();
    }
}
